using UnityEngine;
using UnityEngine.UI;

namespace Lean.Localization
{
	[ExecuteInEditMode]
	[DisallowMultipleComponent]
	[RequireComponent(typeof(Image))]
	public class LeanLocalizedImage : LeanLocalizedBehaviour
	{
		[Tooltip("If PhraseName couldn't be found, this sprite will be used")]
		public Sprite FallbackSprite;

		public override void UpdateTranslation(LeanTranslation translation)
		{
			Image component = GetComponent<Image>();
			if (translation != null)
			{
				component.sprite = (translation.Object as Sprite);
			}
			else
			{
				component.sprite = FallbackSprite;
			}
		}

		protected virtual void Awake()
		{
			if (FallbackSprite == null)
			{
				Image component = GetComponent<Image>();
				FallbackSprite = component.sprite;
			}
		}
	}
}
